<%@tag description="page navigator" pageEncoding="utf-8"%>
<%@ attribute name="recordCount" type="java.lang.Integer" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Integer" required="true"%>

<%
Integer o = (Integer)jspContext.getAttribute("recordCount");
int recordCount = o.intValue();

o = (Integer)jspContext.getAttribute("pageSize");
int pageSize = o.intValue();

int pageCount = recordCount / pageSize;
if (pageCount * pageSize < recordCount) ++pageCount;
%>

<%
String uri = (String)request.getAttribute("javax.servlet.forward.request_uri");
String query = request.getQueryString();
String url = "";
String pt = "page=[0-9]+";

int currentPage = 1;
if (request.getParameter("page") != null) {
    currentPage = Integer.parseInt(request.getParameter("page"));
    url = uri + "?" + query;
} else {
    if (query == null) url = uri + "?page=1";
    else url = uri + "?" + query + "&page=1";
}
if (currentPage > pageCount) currentPage = pageCount;
int base = ((currentPage - 1) / 10) * 10;
%>
<style type="text/css">
  a.pager { text-decoration: none; color: blue; font-Size:9pt; width:15px; }
  b.pager { width:15px; }
</style>
<div class="pagination">
<ul>
<li>
<% if (base > 0) { %>
    <a href="<%= url.replaceAll(pt, "page=" + base) %>">≪</a>
<% } %>
</li>
<% for (int i=1; i<=10; ++i) { %>
  <% int n = base + i; %>
  <% if (n > pageCount) break; %>
  <% if (n == currentPage) { %>
      <li><a><%= currentPage %></a></a>
  <% } else { %>
      <li><a href='<%= url.replaceAll(pt, "page=" + n) %>'><%=n%></a></li>
  <% } %>
<% } %>
<li>
<% if (base+11 <= pageCount) { %>
   <a href='<%= url.replaceAll(pt, "page=" + (base+11)) %>'>≫</a>
<% } %>
</li>
</ul>
</div>